
> #code written for R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
> 
> #Load required packages
> #tidyverse v2.0.0
> library(tidyverse)

> #ggrepel v0.9.5
> library(ggrepel)

> #ggthemes v5.1.0
> library(ggthemes)

> #MASS v7.3-60.0.1
> library(MASS)

> #mlogit v1.1-1
> library(mlogit)

> data <- read.csv("tweets_cleaned.csv")

> memdata <- read.csv("original_memdata.csv")

> #Creating Figures 1 and S1
> frequency1 <- read.csv("safig1data.csv")

> frequency2 <- read.csv("fig1data.csv")

> #Figure S1 - Most Used Words as a Proportion of Partisan Vocabulary
> frequency1a <- subset(frequency1, frequency1$rank_Both <= 100)

> pos <- position_jitter(width = 0.001, seed = 10)

> p1 <- ggplot(frequency1a, aes(x = dem_proportion, y = rep_proportion)) +
+   geom_abline(color = "gray60", lty = 2) +
+   geom_point(alpha = 0.8, size = 1.5, aes(color = dictionary)) +
+   geom_text_repel(aes(label = feature2),
+                   min.segment.length = Inf, 
+                   max.overlaps = Inf,
+                   box.padding = 0.1,
+                   fontface = "bold",
+                   force = 5) +
+   scale_color_manual(values = c("blue", "gray40", "red")) +
+   coord_cartesian(xlim=c(0,0.016), ylim=c(0,0.016)) +
+   theme_hc() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.position="none",
+         axis.text.x = element_text(margin = margin(t=-5)),
+         axis.ticks = element_blank()) +
+   labs(y = "Proportion of Republican vocabulary", 
+        x = "Proportion of Democratic vocabulary") +
+   ggtitle("")

> p1

> #Figure 1 - Frequency of Usage for Dictionary Terms
> freq_insurrect <- subset(frequency2, frequency2$dictionary == "insurrection")

> freq_protest <- subset(frequency2, frequency2$dictionary == "protest")

> fig1a <- ggplot(freq_insurrect, aes(x = reorder(feature2, frequency_Both), 
+                                     y = frequency_Both)) +
+   geom_point() + 
+   coord_flip() +
+   ylim(0,300) +
+   labs(x = NULL, y = "Frequency") +
+   ggtitle("Attack on Democracy Dictionary") +
+   theme_hc() +
+   theme(plot.title = element_text(hjust=0.5), 
+         legend.position="none",
+         axis.text.x = element_text(margin = margin(t=-5)),
+         axis.ticks = element_blank())

> fig1a

> fig1b <- ggplot(freq_protest, aes(x = reorder(feature2, frequency_Both), 
+                                   y = frequency_Both)) +
+   geom_point() + 
+   coord_flip() +
+   ylim(0,300) +
+   labs(x = NULL, y = "Frequency") +
+   ggtitle("Lawless Protest Dictionary") +
+   theme_hc() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.position="none",
+         axis.text.x = element_text(margin = margin(t=-5)),
+         axis.ticks = element_blank())

> fig1b

> #Figure 3 - Frame utilization at tweet level
> #recreating Figure 3A
> data <- data %>%
+   mutate(frame = ifelse(democracy == 1, "insurrect",
+                         ifelse(protestonly == 1, "protest", 
+                                ifelse(neither == 1, "neither", NA))))

> data$frame <- as.factor(data$frame)

> data$frame <- factor(data$frame, levels=c('insurrect', 'protest', 'neither'))

> #Figure 3A
> data$democrat <- as.factor(data$democrat)

> fig3a <- ggplot(data, aes(x = frame, fill = democrat)) +
+   geom_bar() +
+   labs(x = "Frame of Tweet", y = "Number of Tweets") + 
+   ggtitle("Frame Utilization by Tweet") +
+   scale_fill_manual(values=c('red', 'blue'), labels=c('Republicans', 'Democrats'), name="") +
+   scale_x_discrete(labels = c('Attack on Democracy', 'Lawless Protest', 'Neither')) +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.position = "bottom",
+         legend.margin=margin(t=-2))

> fig3a

> #Figure 3B
> sums <- data %>%
+   group_by(democrat, chamber) %>%
+   summarise(insurrection = mean(demonly, na.rm = TRUE), 
+             protest = mean(protestonly, na.rm = TRUE),
+             both = mean(both, na.rm = TRUE),
+             neither = mean(neither, na.rm = TRUE)) %>%
+   pivot_longer(!democrat & !chamber, names_to = "frame", values_to = "proportion") %>%
+   mutate(group = ifelse(democrat == 0 & chamber == "House", "House Rs",
+                         ifelse(democrat == 0 & chamber == "Senate", "Senate Rs",
+                                ifelse(democrat == 1 & chamber == "House", "House Ds", "Senate Ds"))))
`summarise()` has grouped output by 'democrat'. You can override using the `.groups` argument.

> sums$frame <- factor(sums$frame, levels=c('protest', 'neither', 'both', 'insurrection'))

> sums$group <- as.factor(sums$group)

> fig3b <- ggplot(sums, aes(fill = frame, y = proportion, x = group)) +
+   geom_bar(position = "fill", stat = "identity") + 
+   labs(x = "Posting Member Chamber and Party", y = "Proportion of All Tweets", fill= "Tweet Frame:") + 
+   ggtitle("Proportion of Tweets in Each Frame") +
+   scale_x_discrete(labels=c('House Ds', 'House Rs', 
+                             'Senate Ds', 'Senate Rs')) +
+   scale_fill_manual(values = c("#5c055c", "gray70", "#377d37", "#055305"), 
+                     labels = c("Protest", "Neither", "Both", "Democracy")) +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.position = "bottom",
+         legend.margin=margin(t=-2),
+         axis.title.x = element_text(margin = margin(t=5))) +
+   coord_flip()

> fig3b

> #Table S3 - Topics identified in tweets using neither frame
> data <- data %>%
+   mutate(neither_topic2 = case_when(
+     neither_topic == "election generic" | neither_topic == "election legitimate" | neither_topic == "election objection" | neither_topic == "persevere" ~ "election",
+     neither_topic == "generic condemn" | neither_topic == "trump sucks" ~ "condemn",
+     neither_topic == "safe" | neither_topic == "status update" ~ "safe",
+     neither_topic == "see my statement" | neither_topic == "unclear" | neither_topic == "off-topic" ~ "misc",
+     TRUE ~ NA
+   ))

> neithers <- subset(data, neither == 1)

> top <- neithers %>%
+   group_by(neither_topic2, democrat) %>%
+   summarise(n=n())
`summarise()` has grouped output by 'neither_topic2'. You can override using the `.groups`
argument.

> all <- neithers %>%
+   group_by(neither_topic) %>%
+   summarise(n=n())

> dems <- subset(neithers, democrat == 1)

> reps <- subset(neithers, democrat == 0)

> d1 <- dems %>%
+   group_by(neither_topic) %>%
+   summarise(n=n())

> r1 <- reps %>%
+   group_by(neither_topic) %>%
+   summarise(n=n())

> all <- left_join(all, d1, by="neither_topic")

> all <- left_join(all, r1, by="neither_topic")

> colnames(all) <- c("neither_topic", "total", "d_total", "r_total")

> all[is.na(all)] <- 0

> all$d_pct <- all$d_total/all$total

> all$r_pct <- all$r_total/all$total

> print(all)
# A tibble: 11 × 6
   neither_topic       total d_total r_total d_pct r_pct
   <chr>               <int>   <int>   <int> <dbl> <dbl>
 1 election generic       27      13      14 0.481 0.519
 2 election legitimate    72      60      12 0.833 0.167
 3 election objection     47       0      47 0     1    
 4 external               33      14      19 0.424 0.576
 5 generic condemn       161      71      90 0.441 0.559
 6 off-topic              53      39      14 0.736 0.264
 7 other update           99      69      30 0.697 0.303
 8 return                 84      69      15 0.821 0.179
 9 safe                  176     139      37 0.790 0.210
10 trump                  84      73      11 0.869 0.131
11 unclear                88      60      28 0.682 0.318

> #Figure 4 - Tweet usage over time
> #Figure 4A
> data <- data %>%
+   mutate(all_topic = case_when(
+     democracy == 1 ~ "insurrection",
+     protestonly == 1 ~ "protest",
+     neither == 1 ~ neither_topic2,
+     TRUE ~ NA
+   ))

> overtime1 <- data  %>%
+   group_by(time_bin, all_topic) %>%
+   summarise(n = n()) %>%
+   mutate(percentage = n / sum(n))
`summarise()` has grouped output by 'time_bin'. You can override using the `.groups` argument.

> overtime1$all_topic <- fct_relevel(overtime1$all_topic,
+                                    "misc", "election", "condemn", 
+                                    "safe", "protest", "insurrection")

> fig4a <- ggplot(overtime1, aes(x=time_bin, y=n, fill=all_topic)) +
+   geom_area() +
+   labs(x = "", y = "Number of Tweets", fill="") +
+   ggtitle("All Tweets by Hour") +
+   theme_bw() +
+   scale_fill_manual(values = c("gray80", "gray60", "gray40", "gray20", "darkorchid4", "darkgreen"),
+                     labels = c("Miscellaneous", "Floor Proceedings", "General Condemnation", "Status Update", "Lawless Protest", "Attack on Democracy")) +
+   scale_x_continuous(breaks = 2:9,
+                      labels = c("1pm-2pm\nCapitol barriers\nbreached", "2pm-3pm\nVP evacuated;\nAshli Babbitt shot", "3pm-4pm", "4pm-5pm\nTrump video\n'Go Home'", "5pm-6pm\nCrowd thins out", "6pm-7pm\nCapitol Police\n'All Clear'","7pm-8pm","8pm-9pm\nPence reopens\nthe Senate")) +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.position = "bottom",
+         legend.margin=margin(t=-10),
+         axis.title.x = element_text(margin = margin(t=5)))

> fig4a

> #Figure 2 - Tweet frequency and frame utilization at member level
> 
> #Figure 2A
> memdata$democrat <- as.factor(memdata$democrat)

> fig2a <- ggplot(memdata, aes(x = mem_tweet_count, fill = democrat, color = democrat)) +
+   geom_density(alpha=0.75) +
+   scale_fill_manual(values = c('red', 'blue'), labels = c('Republicans', 'Democrats'), name="") +
+   scale_color_manual(values = c('red', 'blue'), labels = c('Republicans', 'Democrats'), name="") +
+   labs(x = "Number of Tweets Posted", y = "Density") +
+   ggtitle("Tweet Frequency by Member") +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.position="bottom",
+         legend.margin=margin(t=-2))

> fig2a

> #Figure 2B
> memdata$demever <- ifelse(memdata$dem_total_mem > 0, 1, 0)

> memdata$protever <- ifelse(memdata$prot_total_mem > 0, 1, 0)

> memdata$nonever <- ifelse(memdata$demever == 0 & memdata$protever == 0, 1, 0)

> memdata$bothever <- ifelse(memdata$demever == 1 & memdata$protever == 1, 1, 0)

> memdata$demonly <- ifelse(memdata$demever == 1 & memdata$protever == 0, 1, 0)

> memdata$protonly <- ifelse(memdata$demever == 0 & memdata$protever == 1, 1, 0)

> memdata <- memdata %>%
+   mutate(member_frame = case_when(demonly == 1 ~ "insurrect",
+                                   protonly == 1 ~ "protest",
+                                   bothever == 1 ~ "both",
+                                   nonever == 1 ~ "neither",
+                                   TRUE ~ NA))

> plotdata <- memdata

> plotdata$demever <- as.factor(plotdata$demever)

> plotdata$protever <- as.factor(plotdata$protever)

> plotdata$nonever <- as.factor(plotdata$nonever)

> plotdata$democrat <- as.factor(plotdata$democrat)

> plotdata$framechoice <- as.factor(plotdata$member_frame)

> plotdata$framechoice <- fct_relevel(plotdata$framechoice,
+                                     "insurrect", "protest", "both",
+                                     "neither")

> fig2b <- ggplot(plotdata, aes(x = framechoice, fill = democrat)) +
+   geom_bar() + 
+   scale_fill_manual(values=c('red', 'blue'), labels=c('Republicans', 'Democrats'), name="") +
+   scale_x_discrete(labels=c('Democracy\nTweets Only','Protest\nTweets Only', 'Democracy and\nProtest Tweets', 'Neither\nTweets')) +
+   xlab("Category of Tweets Posted") +
+   ylab("Number of Members") +
+   ggtitle("Frame Utilization by Member") +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.position = "bottom",
+         legend.margin=margin(t=-2),
+         axis.title.x = element_text(margin = margin(t=5)))

> fig2b

> #Table S4 - Negative binomial model 
> memdata$leader <- memdata$maj_leader + memdata$min_leader

> memdata$trump_margin2 <- memdata$trump_margin/10

> memdata$votemargin2 <- memdata$votemargin/10

> memdata$lntweetpy <- log(memdata$user_tweet_peryear)

> mem_all3a <- glm.nb(mem_tweet_count ~ lntweetpy +
+                       democrat +
+                       seniority + 
+                       leader +
+                       votemargin2 +
+                       trump_margin2 +
+                       chamber,
+                     data = memdata)

> summary(mem_all3a)

Call:
glm.nb(formula = mem_tweet_count ~ lntweetpy + democrat + seniority + 
    leader + votemargin2 + trump_margin2 + chamber, data = memdata, 
    init.theta = 3.690801536, link = log)

Coefficients:
               Estimate Std. Error z value Pr(>|z|)    
(Intercept)   -1.863678   0.394686  -4.722 2.34e-06 ***
lntweetpy      0.437003   0.055989   7.805 5.94e-15 ***
democrat1      0.211023   0.114831   1.838 0.066109 .  
seniority      0.002245   0.008550   0.263 0.792905    
leader        -0.168662   0.126878  -1.329 0.183740    
votemargin2    0.008938   0.018252   0.490 0.624370    
trump_margin2 -0.061023   0.019145  -3.187 0.001435 ** 
chamberSenate -0.344280   0.099009  -3.477 0.000507 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for Negative Binomial(3.6908) family taken to be 1)

    Null deviance: 712.69  on 524  degrees of freedom
Residual deviance: 512.46  on 517  degrees of freedom
  (12 observations deleted due to missingness)
AIC: 2295.6

Number of Fisher Scoring iterations: 1


              Theta:  3.691 
          Std. Err.:  0.452 

 2 x log-likelihood:  -2277.569 

> #calculating chi squared
> mem_base <- glm.nb(mem_tweet_count ~ 1,
+                    data = memdata)

> anova(mem_base, mem_all3a, test = "Chisq")
Likelihood ratio tests of Negative Binomial Models

Response: mem_tweet_count
                                                                              Model    theta
1                                                                                 1 2.014162
2 lntweetpy + democrat + seniority + leader + votemargin2 + trump_margin2 + chamber 3.690802
  Resid. df    2 x log-lik.   Test    df LR stat. Pr(Chi)
1       536       -2503.076                              
2       517       -2277.569 1 vs 2    19 225.5065       0

> #Figure 5 - Model results for number of tweets posted by member
> #Figure 5A - Coefficient plot
> coefs <- as.data.frame(mem_all3a$coefficients)

> coefs$ests <- exp(coefs$`mem_all3a$coefficients`)

> coefs$se <- sqrt(diag(vcov(mem_all3a)))

> coefs$vars <- rownames(coefs)

> colnames(coefs) <- c("coefs", "ests", "se", "vars")  

> coefs$lb <- coefs$coefs - 1.96*coefs$se

> coefs$ub <- coefs$coefs + 1.96*coefs$se

> coefs <- coefs %>%
+   filter(vars!="(Intercept)") %>%
+   mutate(vars = recode(vars,
+                        "lntweetpy" = "Tweets per Year",
+                        "democrat1" = "Democrat",
+                        "seniority" = "Seniority",
+                        "leader" = "Leadership",
+                        "votemargin2" = "Electoral Safety",
+                        "trump_margin2" = "Trump Margin",
+                        "chamberSenate" = "Senator"
+   ))

> coefs$vars <- fct_relevel(coefs$vars,
+                           "Electoral Safety",
+                           "Leadership",
+                           "Seniority",
+                           "Democrat",
+                           "Senator",
+                           "Trump Margin",
+                           "Tweets per Year")

> fig5a <- ggplot(coefs, aes(vars, coefs)) + 
+   geom_hline(yintercept=0, lty=3, colour="grey50") +
+   geom_errorbar(aes(ymin=lb, ymax=ub), width=0) +
+   geom_point(size=2) +
+   coord_flip() +
+   ylim(-0.6,0.6) +
+   xlab("") +
+   ylab("Estimated Coefficients\n(with 95% confidence intervals)") +
+   ggtitle("Negative Binomial Model Results") +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         axis.ticks = element_blank(),
+         legend.position = "none") 

> fig5a

> mem.dems <- subset(memdata, memdata$democrat == 1)

> mem.reps <- subset(memdata, memdata$democrat == 0)

> #Figure 5B - nb predictions
> ppdata.d <- with(mem.dems, data.frame(lntweetpy = median(lntweetpy, na.rm = TRUE),
+                                       democrat = 1,
+                                       seniority = median(seniority, na.rm = TRUE),
+                                       leader = 0,
+                                       chamber = "House",
+                                       votemargin2 = median(votemargin2, na.rm = TRUE),
+                                       trump_margin2 = seq(from=-6.5, to=1.5, by=.5)))

> ppdata.r <- with(mem.reps, data.frame(lntweetpy = median(lntweetpy, na.rm = TRUE),
+                                       democrat = 0,
+                                       seniority = median(seniority, na.rm = TRUE),
+                                       leader = 0,
+                                       chamber = "House",
+                                       votemargin2 = median(votemargin2, na.rm = TRUE),
+                                       trump_margin2 = seq(from=-1.5, to=6.5, by=.5)))

> ppdata <- rbind(ppdata.d, ppdata.r)

> ppdata$democrat <- as.factor(ppdata$democrat)

> ppdata <- cbind(ppdata, predict(mem_all3a, newdata = ppdata, se=TRUE, type = "response"))

> ppdata$trump_margin2 <- ppdata$trump_margin2*10

> fig5b <- ggplot(ppdata, aes(x=trump_margin2, y=fit, group=democrat)) +
+   geom_ribbon(aes(ymin=fit-se.fit, ymax=fit+se.fit, fill = democrat), alpha = 0.2) +
+   geom_line(aes(color = democrat), linewidth=1) +
+   scale_color_manual(name = "",
+                      values=c("red", "blue"),
+                      labels=c("Republican","Democrat")) +
+   scale_fill_manual(name = "",
+                     values=c("red", "blue"),
+                     labels=c("Republican","Democrat")) +
+   scale_x_continuous(breaks = seq(-60, 60, by = 30)) +
+   labs(x = "Trump Margin of Victory", y = "Predicted Number of Tweets") +
+   ggtitle("Negative Binomial Model Predictions") +
+   ylim(0,7) +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.margin=margin(t=-2),
+         legend.position = "bottom")

> fig5b

> #Table S5 - Multinomial logistic regression results for all tweets
> #creating variables for ML models
> data <- data %>%
+   mutate(quotetweet = case_when(sourcetweet_type == "quoted" ~ 1,
+                                 TRUE ~ 0),
+          replytweet = case_when(!is.na(in_reply_to_user_id) ~ 1,
+                                 TRUE ~ 0),
+          thread = case_when(author_id == in_reply_to_user_id ~ 1, 
+                             TRUE ~ 0),
+          tweet_type = case_when(thread == 1 ~ 'Thread',
+                                 thread == 0 & replytweet == 1 ~ 'Reply',
+                                 quotetweet == 1 ~ 'Quote',
+                                 TRUE ~ 'Original'))

> data$tweet_type <- as.factor(data$tweet_type)

> data$leader <- data$maj_leader + data$min_leader

> data$trump_margin2 <- data$trump_margin/10

> data$votemargin2 <- data$votemargin/10

> data <- data %>%
+   mutate(h2 = case_when(time_bin == 2 ~ 1,
+                         TRUE ~ 0),
+          h3 = case_when(time_bin == 3 ~ 1,
+                         TRUE ~ 0),
+          h4 = case_when(time_bin == 4 ~ 1,
+                         TRUE ~ 0),
+          h5 = case_when(time_bin == 5 ~ 1,
+                         TRUE ~ 0),
+          h6 = case_when(time_bin == 6 ~ 1,
+                         TRUE ~ 0),
+          h7 = case_when(time_bin == 7 ~ 1,
+                         TRUE ~ 0),
+          h8 = case_when(time_bin == 8 ~ 1,
+                         TRUE ~ 0),
+          h9 = case_when(time_bin == 9 ~ 1,
+                         TRUE ~ 0))

> mldata <- mlogit.data(data, varying=NULL, choice="frame", shape="wide")

> #this is the actual model in Table S5
> mlmodel1b <- mlogit(frame ~ 1 | democrat + 
+                       trump_margin2 +
+                       factor(time_bin) + 
+                       votemargin2 +
+                       primary +
+                       seniority +
+                       leader +
+                       tweet_type,
+                     data = mldata, reflevel = "neither")

> summary(mlmodel1b)

Call:
mlogit(formula = frame ~ 1 | democrat + trump_margin2 + factor(time_bin) + 
    votemargin2 + primary + seniority + leader + tweet_type, 
    data = mldata, reflevel = "neither", method = "nr")

Frequencies of alternatives:choice
  neither insurrect   protest 
  0.49620   0.32682   0.17698 

nr method
6 iterations, 0h:0m:0s 
g'(-H)^-1g = 0.000181 
successive function values within tolerance limits 

Coefficients :
                             Estimate Std. Error z-value  Pr(>|z|)    
(Intercept):insurrect       -1.793392   0.250524 -7.1586 8.153e-13 ***
(Intercept):protest         -1.830811   0.335679 -5.4541 4.923e-08 ***
democrat1:insurrect          1.217069   0.222730  5.4643 4.647e-08 ***
democrat1:protest           -1.345037   0.254130 -5.2927 1.205e-07 ***
trump_margin2:insurrect     -0.050780   0.036942 -1.3746 0.1692564    
trump_margin2:protest        0.015032   0.040739  0.3690 0.7121329    
factor(time_bin)3:insurrect  0.293938   0.215590  1.3634 0.1727530    
factor(time_bin)3:protest    1.852200   0.333944  5.5464 2.915e-08 ***
factor(time_bin)4:insurrect  0.280917   0.209579  1.3404 0.1801188    
factor(time_bin)4:protest    1.880131   0.323008  5.8207 5.860e-09 ***
factor(time_bin)5:insurrect  0.746013   0.206370  3.6149 0.0003004 ***
factor(time_bin)5:protest    1.583296   0.338410  4.6786 2.888e-06 ***
factor(time_bin)6:insurrect  0.724363   0.232600  3.1142 0.0018445 ** 
factor(time_bin)6:protest    1.382561   0.375596  3.6810 0.0002323 ***
factor(time_bin)7:insurrect  0.882227   0.242099  3.6441 0.0002684 ***
factor(time_bin)7:protest    1.779548   0.379965  4.6834 2.821e-06 ***
factor(time_bin)8:insurrect  1.134468   0.233897  4.8503 1.233e-06 ***
factor(time_bin)8:protest    1.082103   0.425299  2.5443 0.0109487 *  
factor(time_bin)9:insurrect  0.779229   0.221873  3.5120 0.0004447 ***
factor(time_bin)9:protest    0.622260   0.440839  1.4115 0.1580873    
votemargin2:insurrect       -0.073627   0.036485 -2.0180 0.0435897 *  
votemargin2:protest         -0.022536   0.034697 -0.6495 0.5160025    
primary:insurrect            0.084862   0.141589  0.5994 0.5489374    
primary:protest              0.419565   0.174106  2.4098 0.0159600 *  
seniority:insurrect          0.022063   0.013777  1.6014 0.1092807    
seniority:protest            0.019658   0.018397  1.0685 0.2852738    
leader:insurrect            -0.166977   0.201932 -0.8269 0.4082955    
leader:protest              -0.267062   0.306703 -0.8708 0.3838898    
tweet_typeQuote:insurrect   -0.476513   0.175912 -2.7088 0.0067524 ** 
tweet_typeQuote:protest     -0.632804   0.265379 -2.3845 0.0171011 *  
tweet_typeReply:insurrect   -3.203279   0.601218 -5.3280 9.931e-08 ***
tweet_typeReply:protest     -3.034546   1.018395 -2.9797 0.0028850 ** 
tweet_typeThread:insurrect  -0.103318   0.154667 -0.6680 0.5041303    
tweet_typeThread:protest    -0.031508   0.191936 -0.1642 0.8696059    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log-Likelihood: -1601.5
McFadden R^2:  0.14739 
Likelihood ratio test : chisq = 553.67 (p.value = < 2.22e-16)

> #Table S6 - Multinomial logistic regression results by party
> #split ML data into partisan subgroups
> data.dems <- subset(mldata, mldata$democrat == 1)

> data.reps <- subset(mldata, mldata$democrat == 0)

> #partisan ML models Democrats
> #Table S6 Democratic Tweets
> mlmodel2b <- mlogit(frame ~ 1 | trump_margin2 +
+                       factor(time_bin) + 
+                       votemargin2 +
+                       primary +
+                       seniority +
+                       leader +
+                       tweet_type,
+                     data = data.dems, reflevel = "neither")

> summary(mlmodel2b)

Call:
mlogit(formula = frame ~ 1 | trump_margin2 + factor(time_bin) + 
    votemargin2 + primary + seniority + leader + tweet_type, 
    data = data.dems, reflevel = "neither", method = "nr")

Frequencies of alternatives:choice
  neither insurrect   protest 
 0.488655  0.433549  0.077796 

nr method
6 iterations, 0h:0m:0s 
g'(-H)^-1g = 4.79E-05 
successive function values within tolerance limits 

Coefficients :
                              Estimate Std. Error z-value  Pr(>|z|)    
(Intercept):insurrect       -0.3201981  0.2055647 -1.5577  0.119316    
(Intercept):protest         -2.7317925  0.4443140 -6.1483 7.830e-10 ***
trump_margin2:insurrect     -0.0788498  0.0561721 -1.4037  0.160403    
trump_margin2:protest       -0.1385120  0.1034444 -1.3390  0.180571    
factor(time_bin)3:insurrect  0.1343482  0.2337029  0.5749  0.565381    
factor(time_bin)3:protest    1.3267108  0.4407122  3.0104  0.002609 ** 
factor(time_bin)4:insurrect -0.0190525  0.2289705 -0.0832  0.933685    
factor(time_bin)4:protest    0.7368235  0.4620417  1.5947  0.110777    
factor(time_bin)5:insurrect  0.4537822  0.2248047  2.0186  0.043533 *  
factor(time_bin)5:protest    0.5940006  0.4850823  1.2245  0.220750    
factor(time_bin)6:insurrect  0.4431489  0.2540521  1.7443  0.081103 .  
factor(time_bin)6:protest    0.7198863  0.5350659  1.3454  0.178491    
factor(time_bin)7:insurrect  0.8024217  0.2666098  3.0097  0.002615 ** 
factor(time_bin)7:protest    1.5595186  0.4831368  3.2279  0.001247 ** 
factor(time_bin)8:insurrect  1.1265825  0.2583515  4.3607 1.297e-05 ***
factor(time_bin)8:protest    0.6692354  0.5765270  1.1608  0.245721    
factor(time_bin)9:insurrect  0.6269819  0.2386920  2.6267  0.008621 ** 
factor(time_bin)9:protest    0.4448041  0.5487182  0.8106  0.417582    
votemargin2:insurrect       -0.1050020  0.0573719 -1.8302  0.067220 .  
votemargin2:protest         -0.1648316  0.1068383 -1.5428  0.122876    
primary:insurrect            0.0363515  0.1549044  0.2347  0.814464    
primary:protest              0.2105109  0.2685522  0.7839  0.433114    
seniority:insurrect          0.0091016  0.0149744  0.6078  0.543313    
seniority:protest            0.0309373  0.0261114  1.1848  0.236088    
leader:insurrect            -0.1873247  0.2120628 -0.8833  0.377050    
leader:protest              -0.6765668  0.4883789 -1.3853  0.165951    
tweet_typeQuote:insurrect   -0.3866372  0.1882852 -2.0535  0.040027 *  
tweet_typeQuote:protest     -0.1575988  0.3453799 -0.4563  0.648170    
tweet_typeReply:insurrect   -3.6020666  0.7308300 -4.9287 8.276e-07 ***
tweet_typeReply:protest     -2.4218940  1.0287083 -2.3543  0.018557 *  
tweet_typeThread:insurrect  -0.0557341  0.1764151 -0.3159  0.752059    
tweet_typeThread:protest     0.4938706  0.2943672  1.6777  0.093398 .  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log-Likelihood: -1060.2
McFadden R^2:  0.056798 
Likelihood ratio test : chisq = 127.69 (p.value = 5.114e-14)

> #partisan ML models Republicans
> #Table S6 Republican Tweets
> mlmodel3b <- mlogit(frame ~ 1 | trump_margin2 +
+                       factor(time_bin) + 
+                       votemargin2 +
+                       primary +
+                       seniority +
+                       leader +
+                       tweet_type,
+                     data = data.reps, reflevel = "neither")

> summary(mlmodel3b)

Call:
mlogit(formula = frame ~ 1 | trump_margin2 + factor(time_bin) + 
    votemargin2 + primary + seniority + leader + tweet_type, 
    data = data.reps, reflevel = "neither", method = "nr")

Frequencies of alternatives:choice
  neither insurrect   protest 
  0.51151   0.11020   0.37829 

nr method
16 iterations, 0h:0m:0s 
g'(-H)^-1g = 6.82E-07 
gradient close to zero 

Coefficients :
                               Estimate  Std. Error z-value  Pr(>|z|)    
(Intercept):insurrect         -4.295796    1.063476 -4.0394 5.359e-05 ***
(Intercept):protest           -2.547171    0.504353 -5.0504 4.409e-07 ***
trump_margin2:insurrect       -0.348208    0.138788 -2.5089 0.0121101 *  
trump_margin2:protest          0.079754    0.096489  0.8266 0.4084837    
factor(time_bin)3:insurrect    2.354474    1.093351  2.1534 0.0312835 *  
factor(time_bin)3:protest      2.538038    0.517200  4.9073 9.235e-07 ***
factor(time_bin)4:insurrect    2.563357    1.063067  2.4113 0.0158964 *  
factor(time_bin)4:protest      2.838281    0.497815  5.7015 1.188e-08 ***
factor(time_bin)5:insurrect    3.162901    1.060073  2.9837 0.0028482 ** 
factor(time_bin)5:protest      2.544660    0.517093  4.9211 8.607e-07 ***
factor(time_bin)6:insurrect    3.203820    1.094880  2.9262 0.0034315 ** 
factor(time_bin)6:protest      2.248616    0.564502  3.9834 6.795e-05 ***
factor(time_bin)7:insurrect    2.999924    1.126098  2.6640 0.0077218 ** 
factor(time_bin)7:protest      1.995195    0.590579  3.3784 0.0007292 ***
factor(time_bin)8:insurrect    2.497862    1.165918  2.1424 0.0321614 *  
factor(time_bin)8:protest      1.463456    0.630623  2.3207 0.0203056 *  
factor(time_bin)9:insurrect    2.933070    1.113699  2.6336 0.0084478 ** 
factor(time_bin)9:protest      0.842260    0.719358  1.1708 0.2416593    
votemargin2:insurrect          0.121513    0.091083  1.3341 0.1821732    
votemargin2:protest           -0.043064    0.071267 -0.6043 0.5456711    
primary:insurrect              0.469827    0.385585  1.2185 0.2230423    
primary:protest                0.522545    0.256336  2.0385 0.0414986 *  
seniority:insurrect            0.110114    0.036963  2.9790 0.0028915 ** 
seniority:protest              0.019614    0.029099  0.6740 0.5002803    
leader:insurrect              -0.034955    0.680068 -0.0514 0.9590076    
leader:protest                 0.035448    0.445762  0.0795 0.9366168    
tweet_typeQuote:insurrect     -1.310775    0.761245 -1.7219 0.0850904 .  
tweet_typeQuote:protest       -1.209381    0.409314 -2.9547 0.0031302 ** 
tweet_typeReply:insurrect     -1.313138    1.077654 -1.2185 0.2230281    
tweet_typeReply:protest      -17.582786 1996.620155 -0.0088 0.9929737    
tweet_typeThread:insurrect    -0.144246    0.355921 -0.4053 0.6852760    
tweet_typeThread:protest      -0.372458    0.255994 -1.4550 0.1456828    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log-Likelihood: -504.88
McFadden R^2:  0.12927 
Likelihood ratio test : chisq = 149.91 (p.value = < 2.22e-16)

> #same model but this version lets me make my predicted graph
> mlmodel3b2 <- mlogit(frame ~ 1 | trump_margin2 +
+                        h3+h4+h5+h6+h7+h8+h9+ 
+                        votemargin2 +
+                        primary +
+                        seniority +
+                        leader +
+                        tweet_type,
+                      data = data.reps, reflevel = "neither")

> summary(mlmodel3b2)

Call:
mlogit(formula = frame ~ 1 | trump_margin2 + h3 + h4 + h5 + h6 + 
    h7 + h8 + h9 + votemargin2 + primary + seniority + leader + 
    tweet_type, data = data.reps, reflevel = "neither", method = "nr")

Frequencies of alternatives:choice
  neither insurrect   protest 
  0.51151   0.11020   0.37829 

nr method
16 iterations, 0h:0m:0s 
g'(-H)^-1g = 6.82E-07 
gradient close to zero 

Coefficients :
                              Estimate  Std. Error z-value  Pr(>|z|)    
(Intercept):insurrect        -4.295796    1.063476 -4.0394 5.359e-05 ***
(Intercept):protest          -2.547171    0.504353 -5.0504 4.409e-07 ***
trump_margin2:insurrect      -0.348208    0.138788 -2.5089 0.0121101 *  
trump_margin2:protest         0.079754    0.096489  0.8266 0.4084837    
h3:insurrect                  2.354474    1.093351  2.1534 0.0312835 *  
h3:protest                    2.538038    0.517200  4.9073 9.235e-07 ***
h4:insurrect                  2.563357    1.063067  2.4113 0.0158964 *  
h4:protest                    2.838281    0.497815  5.7015 1.188e-08 ***
h5:insurrect                  3.162901    1.060073  2.9837 0.0028482 ** 
h5:protest                    2.544660    0.517093  4.9211 8.607e-07 ***
h6:insurrect                  3.203820    1.094880  2.9262 0.0034315 ** 
h6:protest                    2.248616    0.564502  3.9834 6.795e-05 ***
h7:insurrect                  2.999924    1.126098  2.6640 0.0077218 ** 
h7:protest                    1.995195    0.590579  3.3784 0.0007292 ***
h8:insurrect                  2.497862    1.165918  2.1424 0.0321614 *  
h8:protest                    1.463456    0.630623  2.3207 0.0203056 *  
h9:insurrect                  2.933070    1.113699  2.6336 0.0084478 ** 
h9:protest                    0.842260    0.719358  1.1708 0.2416593    
votemargin2:insurrect         0.121513    0.091083  1.3341 0.1821732    
votemargin2:protest          -0.043064    0.071267 -0.6043 0.5456711    
primary:insurrect             0.469827    0.385585  1.2185 0.2230423    
primary:protest               0.522545    0.256336  2.0385 0.0414986 *  
seniority:insurrect           0.110114    0.036963  2.9790 0.0028915 ** 
seniority:protest             0.019614    0.029099  0.6740 0.5002803    
leader:insurrect             -0.034955    0.680068 -0.0514 0.9590076    
leader:protest                0.035448    0.445762  0.0795 0.9366168    
tweet_typeQuote:insurrect    -1.310775    0.761245 -1.7219 0.0850904 .  
tweet_typeQuote:protest      -1.209381    0.409314 -2.9547 0.0031302 ** 
tweet_typeReply:insurrect    -1.313138    1.077654 -1.2185 0.2230281    
tweet_typeReply:protest     -17.582786 1996.620155 -0.0088 0.9929737    
tweet_typeThread:insurrect   -0.144246    0.355921 -0.4053 0.6852760    
tweet_typeThread:protest     -0.372458    0.255994 -1.4550 0.1456828    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log-Likelihood: -504.88
McFadden R^2:  0.12927 
Likelihood ratio test : chisq = 149.91 (p.value = < 2.22e-16)

> #Figure 6 - Model results for frame utilization by tweet
> #Figure 6A - predicted frame by party
> ppdata.ml <- predict(mlmodel1b, newdata = mldata, se=TRUE, type = "response")

> ppdata.small <- data %>%
+   select(frame, democrat, trump_margin2, time_bin, 
+          votemargin, primary, seniority, leader, tweet_type)

> ppdata.small <- na.omit(ppdata.small)

> ppdata.ml <- cbind(ppdata.ml, ppdata.small)

> ppdata.ml <- ppdata.ml %>%
+   pivot_longer(cols = 1:3,
+                names_to = "outcome",
+                values_to = "fit")

> ppdata.ml$outcome <- fct_relevel(ppdata.ml$outcome,
+                                  "insurrect", "protest", "neither")

> ppdata.ml$democrat <- as.factor(ppdata.ml$democrat)

> fig6a <- ggplot(ppdata.ml, aes(x=outcome, y=fit, fill=democrat)) +
+   geom_boxplot(aes(fill = democrat), alpha = .9,
+                outlier.shape = NA) + 
+   scale_fill_manual(name = "",
+                     values=c("red", "blue"),
+                     labels=c("Republican","Democrat")) +
+   scale_x_discrete(breaks=c("insurrect", "protest", "neither"),
+                    labels=c("Attack on Democracy", "Lawless Protest", "Neither")) +
+   coord_cartesian(ylim = c(0,1)) +
+   xlab("") +
+   ylab("Probability of Frame") +
+   ggtitle("Predicted Frame by Party") +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.margin=margin(t=-15),
+         legend.position = "bottom")

> fig6a

> #figure 6B - predicted frame for republican tweets
> ppdata.r <- with(data.reps, data.frame(frame = c("democracy", "democracy","democracy","democracy",
+                                                  "neither","neither","neither","neither","neither",
+                                                  "protest","protest","protest","protest","protest",
+                                                  "protest"), 
+                                        trump_margin2 = seq(from=-1, to=6, by=.5),
+                                        h3 = 0, h4 = 1, h5 = 0, h6 = 0, h7 = 0, h8 = 0, h9 = 0,
+                                        votemargin2 = median(votemargin2, na.rm = TRUE),
+                                        primary = median(primary, na.rm = TRUE),
+                                        seniority = median(seniority, na.rm = TRUE),
+                                        leader = 0,
+                                        tweet_type = factor("Original", 
+                                                            levels=c("Original", "Quote", "Reply", "Thread"))))

> mlppdata.r <- mlogit.data(ppdata.r, varying=NULL, choice="frame", shape="wide")

> ppdata.rep <- predict(mlmodel3b2, newdata = mlppdata.r, interval = "confidence", type = "response")

> ppdata.rep <- cbind(ppdata.rep, ppdata.r)

> ppdata.rep <- ppdata.rep %>%
+   pivot_longer(cols = 1:3,
+                names_to = "outcome",
+                values_to = "fit")

> ppdata.rep$outcome <- fct_relevel(ppdata.rep$outcome,
+                                   "democracy", "protest", "neither")

> #generating bootstrapped confidence intervals for predicted values
> est_betas <- mlmodel3b2$coefficients

> est_preds <- predict(mlmodel3b2, newdata = mlppdata.r)

> est_ppdata.rep <- cbind(est_preds, ppdata.r)

> est_ppdata.rep <- est_ppdata.rep %>%
+   pivot_longer(cols = 1:3,
+                names_to = "outcome",
+                values_to = "fit")

> est_ppdata.rep <- est_ppdata.rep %>%
+   mutate(order = case_when(outcome == "neither" ~ 1,
+                            outcome == "democracy" ~ 2,
+                            TRUE ~ 3)) %>%
+   arrange(order, trump_margin2)

> set.seed(49)

> sim_betas <- mvrnorm(1000, mlmodel3b2$coefficients, vcov(mlmodel3b2))

> sim_preds <- apply(sim_betas, 1, function(x) {
+   mlmodel3b2$coefficients <- x
+   predict(mlmodel3b2, newdata = mlppdata.r)
+ })

> sim_ci <- apply(sim_preds, 1, quantile, c(.025, .975))

> est_ppdata.rep <- cbind(est_ppdata.rep, t(sim_ci))

> est_ppdata.rep <- est_ppdata.rep %>% 
+   rename(lb = '2.5%') %>%
+   rename(ub = '97.5%')

> est_ppdata.rep$trump_margin2 <- est_ppdata.rep$trump_margin2*10

> fig6b <- ggplot(est_ppdata.rep, aes(x=trump_margin2, y=fit, group=outcome)) +
+   geom_ribbon(aes(ymin=lb, ymax=ub, fill = outcome), alpha = 0.3) +
+   geom_line(aes(color = outcome), linewidth=1) + 
+   labs(x = "Trump Margin of Victory", y = "Probability of Frame Usage") +
+   scale_color_manual(values = c("#055305", "gray70", "#5c005c"), 
+                      labels = c("Attack on Democracy", "Neither", "Lawless Protest"),
+                      name="") +
+   scale_fill_manual(values = c("#055305", "gray70", "#5c005c"), 
+                     labels = c("Attack on Democracy", "Neither", "Lawless Protest"),
+                     name="") +
+   ggtitle("Predicted Frame for Republican Tweets") +
+   ylim(0,1) +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         legend.position = "bottom")

> fig6b

> #Coefficient plots for ML models
> #Figure 6C - Democratic tweets
> coefs.d <- as.data.frame(mlmodel2b$coefficients)

> coefs.d$ests <- exp(coefs.d$`mlmodel2b$coefficients`)

> coefs.d$se <- sqrt(diag(vcov(mlmodel2b)))

> coefs.d$vars <- rownames(coefs.d)

> colnames(coefs.d) <- c("coefs", "ests", "se", "vars")  

> coefs.d$lb <- exp(coefs.d$coefs - 1.96*coefs.d$se)

> coefs.d$ub <- exp(coefs.d$coefs + 1.96*coefs.d$se)

> coefs.d$model <- "Democrats"

> coefs.d <- 
+   coefs.d %>% separate_wider_delim(vars, delim = ":", names = c("var", "frame"))

> coefs.d <- coefs.d %>%
+   filter(var!="(Intercept)" & 
+            var!= "tweet_typeQuote" &
+            var!= "tweet_typeReply" &
+            var!= "tweet_typeThread" &
+            var!= "factor(time_bin)3" &
+            var!= "factor(time_bin)4" &
+            var!= "factor(time_bin)5" &
+            var!= "factor(time_bin)6" &
+            var!= "factor(time_bin)7" &
+            var!= "factor(time_bin)8" &
+            var!= "factor(time_bin)9") %>%
+   mutate(var = recode(var,
+                       "trump_margin2" = "Trump Margin",
+                       "votemargin2" = "Electoral Safety",
+                       "primary" = "Primary",
+                       "seniority" = "Seniority",
+                       "leader" = "Leadership",
+   ))

> coefs.d$var <- fct_relevel(coefs.d$var,
+                            "Electoral Safety",
+                            "Primary",
+                            "Leadership",
+                            "Seniority",
+                            "Trump Margin")

> fig6c <- ggplot(coefs.d, aes(var, ests, color=frame)) + 
+   geom_hline(yintercept=1, lty=3, colour="grey50") +
+   geom_errorbar(aes(ymin=lb, ymax=ub), width=0,
+                 position=position_dodge(width=0.3)) +
+   geom_point(size=2,
+              position=position_dodge(width=0.3)) +
+   scale_color_manual(name = "",
+                      values = c("#377d37", "#5c055c"),
+                      labels = c("Attack on Democracy", "Lawless Protest")) +
+   coord_flip() +
+   ylim(0,3.7) +
+   xlab("") +
+   ylab("Estimated Odds Ratios") +
+   ggtitle("Multinomial Logit Model Results - Democrats") +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         axis.ticks = element_blank(),
+         legend.position = c(0.75, 0.13),
+         legend.title = element_blank())

> fig6c

> #Figure 6D - Republican tweets
> coefs.r <- as.data.frame(mlmodel3b$coefficients)

> coefs.r$ests <- exp(coefs.r$`mlmodel3b$coefficients`)

> coefs.r$se <- sqrt(diag(vcov(mlmodel3b)))

> coefs.r$vars <- rownames(coefs.r)

> colnames(coefs.r) <- c("coefs", "ests", "se", "vars")  

> coefs.r$lb <- exp(coefs.r$coefs - 1.96*coefs.r$se)

> coefs.r$ub <- exp(coefs.r$coefs + 1.96*coefs.r$se)

> coefs.r$model <- "Republicans"

> coefs.r <- 
+   coefs.r %>% separate_wider_delim(vars, delim = ":", names = c("var", "frame"))

> coefs.r <- coefs.r %>%
+   filter(var!="(Intercept)" & 
+            var!= "tweet_typeQuote" &
+            var!= "tweet_typeReply" &
+            var!= "tweet_typeThread" & 
+            var!= "factor(time_bin)3" &
+            var!= "factor(time_bin)4" &
+            var!= "factor(time_bin)5" &
+            var!= "factor(time_bin)6" &
+            var!= "factor(time_bin)7" &
+            var!= "factor(time_bin)8" &
+            var!= "factor(time_bin)9") %>%
+   mutate(var = recode(var,
+                       "trump_margin2" = "Trump Margin",
+                       "votemargin2" = "Electoral Safety",
+                       "primary" = "Primary",
+                       "seniority" = "Seniority",
+                       "leader" = "Leadership",
+   ))

> coefs.r$var <- fct_relevel(coefs.d$var,
+                            "Electoral Safety",
+                            "Primary",
+                            "Leadership",
+                            "Seniority",
+                            "Trump Margin")

> fig6d <- ggplot(coefs.r, aes(var, ests, color=frame)) + 
+   geom_hline(yintercept=1, lty=3, colour="grey50") +
+   geom_errorbar(aes(ymin=lb, ymax=ub), width=0,
+                 position=position_dodge(width=0.3)) +
+   geom_point(size=2,
+              position=position_dodge(width=0.3)) +
+   scale_color_manual(name = "",
+                      values = c("#377d37", "#5c055c"),
+                      labels = c("Attack on Democracy", "Lawless Protest")) +
+   coord_flip() +
+   ylim(0,3.7) +
+   xlab("") +
+   ylab("Estimated Odds Ratios") +
+   ggtitle("Multinomial Logit Model Results - Republicans") +
+   theme_bw() +
+   theme(plot.title = element_text(hjust=0.5),
+         axis.ticks = element_blank(),
+         legend.position = c(0.75, 0.13),
+         legend.title = element_blank())

> fig6d

> #Table S7 - 2022 electoral outcomes by party and frame usage
> electdata <- read.csv("nextelection.csv")

> memdata <- memdata %>%
+   left_join(electdata, by="icpsr")

> memdata <- memdata %>%
+   mutate(reelected = case_when(next_prim_lose == 0 & next_retire_elect == 0 & 
+                                  next_retire == 0 & next_lose_gen == 0 & 
+                                  next_other == 0 ~ 1,
+                                next_prim_lose == 1 | next_retire_elect == 1 |
+                                  next_retire == 1 | next_lose_gen == 1 |
+                                  next_other == 1 ~ 0,
+                                TRUE ~ NA))

> memdata <- memdata %>%
+   mutate(elect_outcome = case_when(reelected == 1 ~ "reelected",
+                                    next_lose_gen == 1 ~ "lost general",
+                                    next_prim_lose == 1 ~ "lost primary",
+                                    next_retire_elect == 1 ~ "other office",
+                                    next_retire == 1 ~ "retired",
+                                    TRUE ~ NA))

> memdata <- memdata %>%
+   mutate(elect_outcome2 = case_when(reelected == 1 ~ "reelected",
+                                     next_lose_gen == 1 ~ "lost",
+                                     next_prim_lose == 1 ~ "lost",
+                                     next_retire_elect == 1 ~ "retired",
+                                     next_retire == 1 ~ "retired",
+                                     TRUE ~ NA))

> memdata$framechoice <- fct_relevel(memdata$member_frame,
+                                       "insurrect", "protest", "both", "neither")

> memdata.el <- subset(memdata, next_elect == 2022)    

> memdata.el <- subset(memdata.el, next_other == 0)

> memdata.el %>%
+   group_by(democrat, framechoice) %>%
+   summarise(n = n(),
+             pchal = mean(next_prim_chal, na.rm = TRUE),
+             ploss = mean(next_prim_lose, na.rm = TRUE),
+             pvote = mean(next_prim_vote, na.rm = TRUE),
+             pcand = mean(next_prim_cand, na.rm = TRUE),
+             ret = mean(next_retire, na.rm = TRUE),
+             ran_other = mean(next_retire_elect, na.rm = TRUE),
+             gloss = mean(next_lose_gen, na.rm = TRUE),
+             reelect = mean(reelected, na.rm = TRUE))
`summarise()` has grouped output by 'democrat'. You can override using the `.groups` argument.
# A tibble: 8 × 11
# Groups:   democrat [2]
  democrat framechoice     n pchal  ploss pvote pcand    ret ran_other   gloss reelect
  <fct>    <fct>       <int> <dbl>  <dbl> <dbl> <dbl>  <dbl>     <dbl>   <dbl>   <dbl>
1 0        insurrect      26 0.783 0.115   66.0  2.83 0.115     0      0         0.769
2 0        protest       123 0.518 0.0163  71.2  2.05 0.0488    0.0325 0.00813   0.894
3 0        both           17 0.538 0       69.9  2.46 0.118     0.118  0         0.765
4 0        neither        61 0.566 0.0328  68.0  2.47 0.0984    0.0328 0.0164    0.820
5 1        insurrect     136 0.244 0.0294  67.6  1.60 0.103     0.0221 0.0147    0.831
6 1        protest        15 0.333 0       63.3  1.44 0.2       0.2    0.0667    0.533
7 1        both           52 0.535 0.0192  77.1  1.93 0.115     0.0577 0.0385    0.769
8 1        neither        33 0.333 0.0303  74.1  1.59 0.121     0.0606 0.0303    0.758

> mem.el.r <- subset(memdata.el, democrat == 0)

> mem.el.d <- subset(memdata.el, democrat == 1)

> chisq.test(mem.el.r$next_prim_chal, mem.el.r$framechoice)

	Pearson's Chi-squared test

data:  mem.el.r$next_prim_chal and mem.el.r$framechoice
X-squared = 5.4941, df = 3, p-value = 0.139


> chisq.test(mem.el.r$next_prim_lose, mem.el.r$framechoice)

	Pearson's Chi-squared test

data:  mem.el.r$next_prim_lose and mem.el.r$framechoice
X-squared = 7.642, df = 3, p-value = 0.05402


> res.aov <- aov(next_prim_vote ~ framechoice, data = mem.el.r)

> summary(res.aov)
             Df Sum Sq Mean Sq F value Pr(>F)
framechoice   3    461   153.7    0.76  0.519
Residuals   110  22256   202.3               
113 observations deleted due to missingness

> res.aov <- aov(next_prim_cand ~ framechoice, data = mem.el.r)

> summary(res.aov)
             Df Sum Sq Mean Sq F value Pr(>F)  
framechoice   3   15.1   5.042   2.137 0.0968 .
Residuals   199  469.4   2.359                 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
24 observations deleted due to missingness

> chisq.test(mem.el.r$next_retire, mem.el.r$framechoice)

	Pearson's Chi-squared test

data:  mem.el.r$next_retire and mem.el.r$framechoice
X-squared = 2.7593, df = 3, p-value = 0.4302


> chisq.test(mem.el.r$next_retire_elect, mem.el.r$framechoice)

	Pearson's Chi-squared test

data:  mem.el.r$next_retire_elect and mem.el.r$framechoice
X-squared = 4.3826, df = 3, p-value = 0.223


> chisq.test(mem.el.r$next_lose_gen, mem.el.r$framechoice)

	Pearson's Chi-squared test

data:  mem.el.r$next_lose_gen and mem.el.r$framechoice
X-squared = 0.79038, df = 3, p-value = 0.8518


> chisq.test(mem.el.r$reelected, mem.el.r$framechoice)

	Pearson's Chi-squared test

data:  mem.el.r$reelected and mem.el.r$framechoice
X-squared = 4.6399, df = 3, p-value = 0.2001


> chisq.test(mem.el.d$next_prim_chal, mem.el.d$framechoice)

	Pearson's Chi-squared test

data:  mem.el.d$next_prim_chal and mem.el.d$framechoice
X-squared = 12.264, df = 3, p-value = 0.006533


> chisq.test(mem.el.d$next_prim_lose, mem.el.d$framechoice)

	Pearson's Chi-squared test

data:  mem.el.d$next_prim_lose and mem.el.d$framechoice
X-squared = 0.5908, df = 3, p-value = 0.8985


> res.aov <- aov(next_prim_vote ~ framechoice, data = mem.el.d)

> summary(res.aov)
            Df Sum Sq Mean Sq F value Pr(>F)
framechoice  3   1420   473.4   1.677  0.181
Residuals   60  16935   282.3               
172 observations deleted due to missingness

> res.aov <- aov(next_prim_cand ~ framechoice, data = mem.el.d)

> summary(res.aov)
             Df Sum Sq Mean Sq F value Pr(>F)
framechoice   3    4.2   1.386   0.805  0.493
Residuals   194  334.2   1.722               
38 observations deleted due to missingness

> chisq.test(mem.el.d$next_retire, mem.el.d$framechoice)

	Pearson's Chi-squared test

data:  mem.el.d$next_retire and mem.el.d$framechoice
X-squared = 1.2767, df = 3, p-value = 0.7347


> chisq.test(mem.el.d$next_retire_elect, mem.el.d$framechoice)

	Pearson's Chi-squared test

data:  mem.el.d$next_retire_elect and mem.el.d$framechoice
X-squared = 10.076, df = 3, p-value = 0.01793


> chisq.test(mem.el.d$next_lose_gen, mem.el.d$framechoice)

	Pearson's Chi-squared test

data:  mem.el.d$next_lose_gen and mem.el.d$framechoice
X-squared = 2.0487, df = 3, p-value = 0.5624


> chisq.test(mem.el.d$reelected, mem.el.d$framechoice)

	Pearson's Chi-squared test

data:  mem.el.d$reelected and mem.el.d$framechoice
X-squared = 7.6164, df = 3, p-value = 0.05464


> #Table S8 - House Republicans casting pro-Trump votes by frame usage
> repvotes <- read.csv("repvotes.csv")

> repvotes <- repvotes %>%
+   select(icpsr, vote_1_AZ_electors, vote_2_PA_electors, vote_3_impeachment,
+          vote_4_national_commission)

> memdata <- left_join(memdata, repvotes, by="icpsr")

> memdata <- memdata %>%
+   mutate(az_vote = case_when(vote_1_AZ_electors == 1 ~ 1,
+                              vote_1_AZ_electors == -1 | vote_1_AZ_electors == 0 ~ 0,
+                              TRUE ~ NA)) %>%
+   mutate(pa_vote = case_when(vote_2_PA_electors == 1 ~ 1,
+                              vote_2_PA_electors == -1 | vote_2_PA_electors == 0 ~ 0,
+                              TRUE ~ NA)) %>%
+   mutate(imp_vote = case_when(vote_3_impeachment == 1 ~ 1,
+                               vote_3_impeachment == -1 | vote_3_impeachment == 0 ~ 0,
+                               TRUE ~ NA)) %>%
+   mutate(comm_vote = case_when(vote_4_national_commission == 1 ~ 1,
+                                vote_4_national_commission == -1 | vote_4_national_commission == 0 ~ 0,
+                                TRUE ~ NA)) %>%
+   mutate(all_votes = case_when(az_vote == 1 & pa_vote == 1 & imp_vote == 1 & comm_vote == 1 ~ 1,
+                                democrat == 1 ~ NA,
+                                chamber == "Senate" ~ NA,
+                                TRUE ~ 0))

> memdata %>%
+   group_by(democrat, framechoice) %>%
+   summarise(az.vot = mean(az_vote, na.rm = TRUE),
+             pa.vot = mean(pa_vote, na.rm = TRUE),
+             imp.vot = mean(imp_vote, na.rm = TRUE),
+             comm.vot = mean(comm_vote, na.rm = TRUE),
+             all.votes = mean(all_votes, na.rm = TRUE))
`summarise()` has grouped output by 'democrat'. You can override using the `.groups` argument.
# A tibble: 8 × 7
# Groups:   democrat [2]
  democrat framechoice  az.vot  pa.vot imp.vot comm.vot all.votes
  <fct>    <fct>         <dbl>   <dbl>   <dbl>    <dbl>     <dbl>
1 0        insurrect     0.375   0.375   0.792    0.583     0.333
2 0        protest       0.667   0.748   0.973    0.858     0.628
3 0        both          0.467   0.6     0.933    1         0.438
4 0        neither       0.534   0.638   0.914    0.842     0.441
5 1        insurrect   NaN     NaN     NaN      NaN       NaN    
6 1        protest     NaN     NaN     NaN      NaN       NaN    
7 1        both        NaN     NaN     NaN      NaN       NaN    
8 1        neither     NaN     NaN     NaN      NaN       NaN    

> chisq.test(memdata$az_vote, memdata$framechoice)

	Pearson's Chi-squared test

data:  memdata$az_vote and memdata$framechoice
X-squared = 8.8548, df = 3, p-value = 0.03129


> chisq.test(memdata$pa_vote, memdata$framechoice)

	Pearson's Chi-squared test

data:  memdata$pa_vote and memdata$framechoice
X-squared = 12.916, df = 3, p-value = 0.004823


> chisq.test(memdata$imp_vote, memdata$framechoice)

	Pearson's Chi-squared test

data:  memdata$imp_vote and memdata$framechoice
X-squared = 11.02, df = 3, p-value = 0.01162


> chisq.test(memdata$comm_vote, memdata$framechoice)

	Pearson's Chi-squared test

data:  memdata$comm_vote and memdata$framechoice
X-squared = 14.032, df = 3, p-value = 0.002863


> chisq.test(memdata$all_votes, memdata$framechoice)

	Pearson's Chi-squared test

data:  memdata$all_votes and memdata$framechoice
X-squared = 10.544, df = 3, p-value = 0.01446

There were 13 warnings (use warnings() to see them)
